package com.aaa.service.impl;

import com.aaa.entity.TestPlanFpa;
import com.aaa.dao.TestPlanFpaDao;
import com.aaa.service.TestPlanFpaService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * 测试计划fpa(TestPlanFpa)表服务实现类
 *
 * @author
 * @since 2022-07-08 09:59:06
 */
@Service("testPlanFpaService")
public class TestPlanFpaServiceImpl implements TestPlanFpaService {
    @Resource
    private TestPlanFpaDao testPlanFpaDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public TestPlanFpa queryById(Integer id) {
        return this.testPlanFpaDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param testPlanFpa 筛选条件
     * @param pageRequest 分页对象
     * @return 查询结果
     */
    @Override
    public Page<TestPlanFpa> queryByPage(TestPlanFpa testPlanFpa, PageRequest pageRequest) {
        long total = this.testPlanFpaDao.count(testPlanFpa);
        return new PageImpl<>(this.testPlanFpaDao.queryAllByLimit(testPlanFpa, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param testPlanFpa 实例对象
     * @return 实例对象
     */
    @Override
    public boolean insert(TestPlanFpa testPlanFpa) {
        //随机生成六位数
        int random = (int) ((Math.random() * 9 + 1) * 100000);
        testPlanFpa.setTestCode(random);
        int insert = this.testPlanFpaDao.insert(testPlanFpa);
        if (insert > 0) {
            return true;
        }
        return false;
    }

    /**
     * 修改数据
     *
     * @param testPlanFpa 实例对象
     * @return 实例对象
     */
    @Override
    public boolean update(TestPlanFpa testPlanFpa) {
        int update = this.testPlanFpaDao.update(testPlanFpa);
        if (update > 0) {
            return true;
        }
        return false;
    }

    /**
     * 通过主键删除数据
     *
     * @param idList 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(String idList) {
        return this.testPlanFpaDao.deleteById(idList) > 0;
    }

    /**
     * @param testPlanFpa
     * @return boolean
     * @create by: feng (zhaixing@163.com)
     * @description: 查询计划名称是否重名
     * @create time: 2022/7/15 15:07
     */
    @Override
    public boolean repetitionName(TestPlanFpa testPlanFpa) {
        Integer integer = this.testPlanFpaDao.repetitionName(testPlanFpa);
        if (integer == 0) {
            return true;
        }
        return false;
    }
}
